package com.company.ThreadLearn;

import java.awt.*;

public class DeadSynchronized {

    final static int LOOP = 1000;

    final Object lockA = new Object();
    final Object lockB = new Object();

    int accountA = 1000;
    int accountB = 2000;

//    public static DeadSynchronized shared = new DeadSynchronized();

    public DeadSynchronized() throws InterruptedException {
        Thread t1 = new AThread();
        Thread t2 = new BThread();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println("END");

    }

    public void a2b(int balance) {
        synchronized (lockA) {
            accountA -= balance;
            synchronized (lockB) {
                accountB -= balance;
            }
        }
    }

    public void b2a(int balance) {
        synchronized (lockB) {
            accountB -= balance;
            synchronized(lockA){
                accountA +=balance;
            }
        }
    }

}

class AThread extends Thread{
    @Override
    public void run() {
        for(int i=0;i<DeadSynchronized.LOOP;i++){

        }
    }
}
class BThread extends Thread {

}